<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""DTD/xhtml1-strict.dtd">
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib uri="/WEB-INF/c.tld" prefix="c"%>
<%@taglib uri="/WEB-INF/fmt.tld" prefix="fmt"%>
<%@taglib uri="/WEB-INF/fn.tld" prefix="fn"%>
<%@taglib uri="/WEB-INF/el.tld" prefix="el"%>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
		<c:import url="/includes/css_inc.jsp"/>
		<c:import url="/includes/js_inc.jsp"/>
		<script>
			$(function(){
	        	var result = "";
				$("#btnSearch").button({
		            icons: {
		                primary: "ui-icon-search"
		            }
		        }).click(function(){
					if(validateEmpty()){
						result = dateDiff($("#startDate").val(), $("#endDate").val(),"/");
			        	if (!result && $("#startDate").val() != "" && $("#endDate").val() != "") {
			        		alert("วันเริ่มต้นต้องน้อยกว่าวันสิ้นสุดกรุณาระบุใหม่");
			        		$("#endDate").val("");
							return false;
			        	} else {
							$("#searchForm").submit();
						}
					} else {
						return false;
					}
		        });
				/* $("#btnExport").button({
		            icons: {
		                primary: "ui-icon-arrowthickstop-1-s"
		            }
				}).click(function(){
					if(validateEmpty()){
						result = dateDiff($("#startDate").val(), $("#endDate").val(),"/");
			        	if (!result) {
			        		alert("วันเริ่มต้นมากกว่าวันสิ้นสุดกรุณาระบุใหม่");
			        		$("#endDate").val("");
							return false;
			        	} else {
			        		window.location='${pageContext.request.contextPath}/acc6?app=ACC60401&job=export&budgetYear='+$("#budgetYear").val()+'&provinceId='+$("#provinceId").val()+"&startDate="+$("#startDate").val()+"&endDate="+$("#endDate").val()+"&type="+$("#type").val()+"&allocateYear="+$("#allocateYear").val();
			        	}
					}	
				}); */
				
				$("#budgetYear").change(function(){
					if ($("#budgetYear").val() != "") {
						$("#startDate").val("01/10/"+($("#budgetYear").val()-1));
					}else {
						$("#startDate").val("");
					}
				});
		        thaiDatepicker("endDate","#","1");
			});
		</script>
	</head>
	<body>
		<c:import url="/apps/msg.jsp"/>
		<form class="acc67-form" name="searchForm" id="searchForm" action="${pageContext.request.contextPath}/acc6" method="post">
		<input type="hidden" name="app" id="app" value="ACC6REPORT"/>
		<input type="hidden" name="job" id="job" value="ACC6REPORT011"/>
		<table width="100%" class="ui-widget ui-widget-content" border="0">
			<tr>
				<th align="left" class="acc67-header ui-widget-header" colspan="2"><b>${screenCode.ACC6REPORT011}</b></th>
			</tr>
			<tr>
				<td class="bold">จังหวัด : </td>
				<td>
					<c:if test="${userInfo.areaLevel =='3'}">
						<c:forEach var="data" items="${userInfo.listUserProvice}">
							${data.provinceName}
							<input type="hidden" name="provinceId" id="provinceId" value="${data.provinceId}">
						</c:forEach>
					</c:if>
					<c:if test="${userInfo.areaLevel=='1' || userInfo.areaLevel=='2'}">
						<select name="provinceId" id="provinceId">
							<option value="">เลือกทั้งหมด</option>
							<c:forEach var="data" items="${userInfo.listUserProvice}">
								<c:if test="${data.provinceId == provinceId}" var="provinceSeleted"/>
								<option value="${data.provinceId}" ${provinceSeleted?'selected':''}>${data.provinceName}</option>
							</c:forEach>
						</select>
					</c:if>
				</td>
			</tr>
			<tr>
				<td class="bold">ปีที่ออกรายงาน : </td>
				<td>
					<select name="budgetYear" id="budgetYear">
						<option value="">----- เลือก -----</option>
						<c:forEach items="${lsBudgetYear}" var="data">
							<c:if test="${budgetYear == data.BUDGET_YEAR}" var="selected"/>
							<option value="${data.BUDGET_YEAR}" ${selected?'selected':''}>${data.BUDGET_YEAR}</option>
						</c:forEach>
					</select>
					<span id="$budgetYear" class="red">*</span>
				</td>
			</tr>
			<tr>
				<td class="bold">วันที่ออกรายงาน : </td>
				<td>
					<input type="text" name="startDate" id="startDate" readonly="readonly" size="12" maxlength="10" onkeypress="return numberAndSlash(event);" onblur="dateFormat(this);" value="${startDate}"/>
					ถึงวันที่
					<input type="text" name="endDate" id="endDate" size="12" maxlength="10" onkeypress="return numberAndSlash(event);" onblur="dateFormat(this);" value="${endDate}"/>
					<span id="#endDate" class="red">*</span>
				</td>
			</tr>
			<tr>
				<td align="center" colspan="2">
					<button type="button" name="btnSearch" id="btnSearch" class="acc67-button"> ค้นหาข้อมูล </button>
					<!-- <button type="button" name="btnExport" id="btnExport" class="acc67-button"> Download </button> -->
				</td>
			</tr>
		</table>
		<br/>
		<c:if test="${!empty listResult}">
			<c:set var="sumIncomeAmount1" value="0"/>
			<c:set var="sumIncomeAmount2" value="0"/>
			<c:set var="sumIncomeAmount3" value="0"/>
			<c:set var="sumIncomeAmountTypeB1" value="0"/>
			<c:set var="sumIncomeAmountTypeB2" value="0"/>
			<c:set var="sumIncomeAmountTypeB3" value="0"/>
			<c:set var="sumAllIncomeAmount" value="0"/>
			<c:set var="sumExpenseAmount" value="0"/>
			<c:set var="remain" value="0"/>
			<c:set var="moneyUseInYear1" value="0"/>
			<c:set var="moneyUseInYear2" value="0"/>
			<c:set var="moneyExpire" value="0"/>
			
			<table width="100%" class="acc67-grid ui-widget ui-widget-content" border="0">
				<%-- <tr>
					<th align="center" width="15%" rowspan="2" class="ui-state-default">รหัสเงินที่ได้รับจัดสรร</th>
					<th colspan="3" align="center" class="ui-state-default">จำนวนเงินที่ได้รับจัดสรร</th>
					<th  align="center" width="6%" rowspan="2" class="ui-state-default">รวม</th>
					<th  align="center" width="6%" rowspan="2" class="ui-state-default">จำนวนเงินที่จ่ายให้หน่วยบริการ</th>
					<th  align="center" width="6%" class="ui-state-default">คงเหลือต้องจัดสรรภายใน</th>
					<th  align="center" width="6%" class="ui-state-default">คงเหลือต้องจัดสรรภายใน</th>
					<th  align="center" width="6%" rowspan="2" class="ui-state-default">จำนวนเงินหมดอายุ</th>
				</tr>
				<tr>
					<th align="center" width="6%" class="ui-state-default">${budgetYear}</th>
					<th align="center" width="6%" class="ui-state-default">${budgetYear - 1 }</th>
					<th align="center" width="6%" class="ui-state-default">${budgetYear - 2} และก่อนหน้า</th>
					<th align="center" width="6%" class="ui-state-default">30/09/${budgetYear}</th>
					<th align="center" width="6%" class="ui-state-default">30/09/${budgetYear+1}</th>
				</tr> --%>
				<tr>
					<th align="center" width="15%" rowspan="3" class="ui-state-default">รหัสเงินที่ได้รับจัดสรร</th>
					<th colspan="6" align="center" class="ui-state-default">จำนวนเงินที่ได้รับจัดสรร</th>
					<th  align="center" width="6%" rowspan="3" class="ui-state-default">รวม</th>
					<th  align="center" width="6%" rowspan="3" class="ui-state-default">จำนวนเงินที่จ่ายให้หน่วยบริการ</th>
					<th  align="center" width="6%" class="ui-state-default">คงเหลือต้องจัดสรรภายใน</th>
					<th  align="center" width="6%" class="ui-state-default">คงเหลือต้องจัดสรรภายใน</th>
					<th  align="center" width="6%" rowspan="3" class="ui-state-default">จำนวนเงินหมดอายุ</th>
				</tr>
				<tr>
					<th align="center" width="6%" class="ui-state-default" colspan="2">${budgetYear}</th>
					<th align="center" width="6%" class="ui-state-default" colspan="2">${budgetYear - 1 }</th>
					<th align="center" width="6%" class="ui-state-default" colspan="2">${budgetYear - 2} และก่อนหน้า</th>
					<th align="center" width="6%" rowspan="2" class="ui-state-default">30/09/${budgetYear}</th>
					<th align="center" width="6%" rowspan="2" class="ui-state-default">30/09/${budgetYear+1}</th>
				</tr>
				<tr>
					<th align="center" width="6%" class="ui-state-default">รับจาก สปสช</th>
					<th align="center" width="6%" class="ui-state-default">ยอดยกมา</th>
					<th align="center" width="6%" class="ui-state-default">รับจาก สปสช</th>
					<th align="center" width="6%" class="ui-state-default">ยอดยกมา</th>
					<th align="center" width="6%" class="ui-state-default">รับจาก สปสช</th>
					<th align="center" width="6%" class="ui-state-default">ยอดยกมา</th>
				</tr>
				
				<c:forEach items="${listResult}" var="data"  varStatus="x">
					<c:if test="${data.allocateLvl == '1'}">
						<tr class="grid-tr-lvl1" >
							<td>
					</c:if>
					<c:if test="${data.allocateLvl == '2'}">
						<tr class="grid-tr-${x.count % 2}" >
							<td> &nbsp;&nbsp;&nbsp;
					</c:if>
							${data.allocateCode} - ${data.allocateName}
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmount1}"/>
							<c:set var="sumIncomeAmount1" value="${sumIncomeAmount1 + data.incomeAmount1}"/>
							<input type="hidden" name="incomeAmount1" id="incomeAmount1" value="${data.incomeAmount1}">
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmountTypeB1}"/>
							<c:set var="sumIncomeAmountTypeB1" value="${sumIncomeAmountTypeB1 + data.incomeAmountTypeB1}"/>
							<input type="hidden" name="incomeAmountTypeB1" id="incomeAmountTypeB1" value="${data.incomeAmountTypeB1}">
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmount2}"/>
							<c:set var="sumIncomeAmount2" value="${sumIncomeAmount2 + data.incomeAmount2}"/>
							<input type="hidden" name="incomeAmount2" id="incomeAmount2" value="${data.incomeAmount2}">
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmountTypeB2}"/>
							<c:set var="sumIncomeAmountTypeB2" value="${sumIncomeAmountTypeB2 + data.incomeAmountTypeB2}"/>
							<input type="hidden" name="incomeAmountTypeB2" id="incomeAmountTypeB2" value="${data.incomeAmountTypeB2}">
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmount3}"/>
							<c:set var="sumIncomeAmount3" value="${sumIncomeAmount3 + data.incomeAmount3}"/>
							<input type="hidden" name="incomeAmount3" id="incomeAmount3" value="${data.incomeAmount3}">
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmountTypeB3}"/>
							<c:set var="sumIncomeAmountTypeB3" value="${sumIncomeAmountTypeB3 + data.incomeAmountTypeB3}"/>
							<input type="hidden" name="incomeAmountTypeB3" id="incomeAmountTypeB3" value="${data.incomeAmountTypeB3}">
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.incomeAmount1 + data.incomeAmount2 + data.incomeAmount3 + data.incomeAmountTypeB1 + data.incomeAmountTypeB2 + data.incomeAmountTypeB3}"/>
							<c:set var="sumAllIncomeAmount" value="${sumAllIncomeAmount + data.incomeAmount1 + data.incomeAmount2 + data.incomeAmount3 + data.incomeAmountTypeB1 + data.incomeAmountTypeB2 + data.incomeAmountTypeB3}"/>
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.expenseAmount}"/>
							<c:set var="sumExpenseAmount" value="${sumExpenseAmount + data.expenseAmount}"/>
							<input type="hidden" name="expenseAmount" id="expenseAmount" value="${data.expenseAmount}">
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.moneyUseInYear2}"/>
							<c:set var="moneyUseInYear2" value="${moneyUseInYear2 + data.moneyUseInYear2}"/>
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.moneyUseInYear1}"/>
							<c:set var="moneyUseInYear1" value="${moneyUseInYear1 + data.moneyUseInYear1}"/>
						</td>
						<td align="right">
							<fmt:formatNumber pattern="#,##0.00" value="${data.moneyExpire}"/>
							<c:set var="moneyExpire" value="${moneyExpire + data.moneyExpire}"/>
						</td>
					</tr>
				</c:forEach>
				<tr>
					<td align="right">รวม</td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumIncomeAmount1}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumIncomeAmountTypeB1}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumIncomeAmount2}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumIncomeAmountTypeB2}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumIncomeAmount3}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumIncomeAmountTypeB3}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumAllIncomeAmount}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${sumExpenseAmount}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${moneyUseInYear2}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${moneyUseInYear1}"/></td>
					<td align="right"><fmt:formatNumber pattern="#,##0.00" value="${moneyExpire}"/></td>
				</tr>
			</table>
		</c:if>
		</form>
	</body>
</html>